<?php

/**
 * Model class representing one TODO item.
 */
final class Content {

    /** @var int */
    private $id;

    /** @var DateTime */
    private $date;

    /** @var string */
    private $title;

    /** @var string */
    private $text;

    /** @var boolean */
    private $valid;

    /** @var int */
    private $category_id;

    /** @var int */
    private $gradesNumber;

    /** @var int */
    private $gradesTotal;

    /** @var string */
    private $userIp;

    /** @var DateTime */
    private $lastModifiedOn;

    /**
     * Create new {@link Todo} with default properties set.
     */
    public function __construct() {
        $now = new DateTime();
        $this->setDate($now);
        $this->setValid(false);
    }

    //~ Getters & setters

    /**
     * @return int <i>null</i> if not persistent
     */
    public function getId() {
        return $this->id;
    }

    public function setId($id) {
        if ($this->id !== null && $this->id != $id) {
            throw new Exception('Cannot change identifier to ' . $id . ', already set to ' . $this->id);
        }
        $this->id = (int) $id;
    }

    public function getDate() {
        return $this->date;
    }

    public function setDate(DateTime $date) {
        $this->date = $date;
    }

    public function getTitle() {
        return $this->title;
    }

    public function setTitle($title) {
        $this->title = $title;
    }

    public function getText() {
        return $this->text;
    }

    public function setText($text) {
        $this->text = $text;
    }

    public function getValid() {
        return $this->valid;
    }

    public function setValid($valid) {
        $this->valid = (bool) $valid;
    }

    public function getCategoryId() {
        return $this->category_id;
    }

    public function setCategoryId($category_id) {
        $this->category_id = $category_id;
    }

    public function getGradesNumber() {
        return $this->gradesNumber;
    }

    public function setGradesNumber($gradesNumber) {
        $this->gradesNumber = $gradesNumber;
    }

    public function getGrade() {
        if ($this->getGradesNumber() != 0) {
            return $this->getGradesTotal() / $this->getGradesNumber();
        } else {
            return 0;
        }
    }

    public function getGradesTotal() {
        return $this->gradesTotal;
    }

    public function setGradesTotal($gradesTotal) {
        $this->gradesTotal = $gradesTotal;
    }

    public function getUserIp() {
        return $this->userIp;
    }

    public function setUserIp($userIp) {
        $this->userIp = $userIp;
    }

    public function getLastModifiedOn() {
        return $this->lastModifiedOn;
    }

    public function setLastModifiedOn(DateTime $lastModifiedOn) {
        $this->lastModifiedOn = $lastModifiedOn;
    }

}

?>
